﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VBDAL;

namespace VBBLL
{
    public class BaseRepositoryBLL<T> where T : class,new()
    {
        //在调用这个方法的时候必须给他赋值
        BaseRepositoryDAL<T> br = new BaseRepositoryDAL<T>();

        //基类的构造函数
        public BaseRepositoryBLL()
        {
            //SetCurrentRepository();  //构造函数里面调用了此设置当前仓储的抽象方法
        }

        //构造方法实现赋值 
        //      public abstract void SetCurrentRepository();  //约束子类必须实现这个抽象方法

        //添加
        public T AddEntities(T entity)
        {
            return br.AddEntities(entity);
        }

        //修改
        public bool UpdateEntities(T entity)
        {
            return br.UpdateEntities(entity);
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public bool DeleteEntities(T entity)
        {
            return br.DeleteEntities(entity);
        }
        /// <summary>
        /// 删除一个链表的内容
        /// </summary>
        /// <param name="entitys"></param>
        /// <returns></returns>
        public bool DeleteEntities(List<T> entitys)
        {
            return br.DeleteEntities(entitys);
        }
        /// <summary>
        /// 根据lambda表达式删除
        /// </summary>
        /// <param name="wherelambda"></param>
        /// <returns></returns>
        public bool DeleteEntities(Func<T, bool> wherelambda)
        {
            return br.DeleteEntities(wherelambda);
        }
        //查询
        public IQueryable<T> LoadEntities(Func<T, bool> wherelambda)
        {
            return br.LoadEntities(wherelambda);
        }
        public IQueryable<T> LoadAllEntities()
        {
            return br.LoadAllEntities();
        }
        //分页
        public IQueryable<T> LoadPagerEntities<S>(int pageSize, int pageIndex,
             out int total, Func<T, bool> whereLambda, bool isAsc, Func<T, S> orderByLambda)
        {
            total = 2;
            return br.LoadPagerEntities(pageSize, pageIndex, out total, whereLambda, isAsc, orderByLambda);
        }

    }
}
